# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Mike Sampson <mike at sambodata dot com>
# Contributor: Dmitry A. Ilyashevich <dmitry.ilyashevich@gmail.com>

pkgbase=distorm
pkgname=('distorm' 'python-distorm')
pkgver=3.5.2.b
_pkgver=${pkgver/.b/b} # Y U NO semver
pkgrel=2
pkgdesc='Powerful disassembler library for x86/AMD64'
url='https://github.com/gdabah/distorm'
arch=('loong64' 'x86_64')
license=('BSD')
makedepends=('python' 'python-setuptools' 'glibc')
options=('staticlibs')
source=(https://github.com/gdabah/distorm/archive/${_pkgver}/${pkgname}-${pkgver}.tar.gz)
sha512sums=('8aad0c51e8d9dfaeaa069a3d4fade4bdf87cce464c85898b6b4888fa51a9bb6ec1221faf32acf59ebd047cceb9a535b2ff93d196fd14fa834d8ece5685417a55')
b2sums=('775d50dbec3858ca4e3ea68fef24be41fcf1b7afd61a6b92e300790895eef7a27ab6b8153cc3258682c006d91d0266425955231b0bd8977a2a186e5e2a8947d5')

build() {
  cd ${pkgbase}-${_pkgver}
  make -C make/linux CFLAGS="${CFLAGS} ${CPPFLAGS} -fPIC"
  python setup.py build
}

package_distorm() {
  depends=('glibc')
  provides=('libdistorm3.so')
  cd ${pkgbase}-${_pkgver}
  make -C make/linux PREFIX=/usr DESTDIR="${pkgdir}" install
  install -Dm 644 include/*.h -t "${pkgdir}/usr/include"
  install -Dm 644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
  ln -sf "/usr/lib/libdistorm3.so.$(grep 'LIB_R_VERSION =' make/linux/Makefile|cut -d' ' -f3)" "${pkgdir}/usr/lib/libdistorm3.so"
}

package_python-distorm() {
  depends=('python')
  cd ${pkgbase}-${_pkgver}
  python setup.py install --root="${pkgdir}" -O1 --skip-build
  install -Dm 644 COPYING -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
